home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / srchlp.zip / SRCHELP.C < prev    next >
C/C++ Source or Header  |  1993-09-18  |  5KB  |  142 lines

  1.  
  2. /******************************************************************************
  3. *                                                                             *
  4. *   Using the internal WinHelp API to search multiple help files for a topic  *
  5. *                                                                             *
  6. *                    9/17/93 by Mark Gamber - Public Domain                   *
  7. *                                                                             *
  8. ******************************************************************************/
  9.  
  10. #include "windows.h"
  11. #include "memory.h"
  12. #include "baggage.h"
  13.  
  14. typedef struct {                   //  This structure defines the layout of the
  15.    FARPROC lpfnUnused;                 //  internal WinHelp functions passed by
  16.    FARPROC lpfnHfsOpenSz;         //  WinHelp to this DLL through LDLLHandler()
  17.    FARPROC lpfnRcCloseHfs;                       //  in the "case 10:" section.
  18.    FARPROC lpfnHfOpenHfs;
  19.    FARPROC lpfnRcCloseHf;
  20.    FARPROC lpfnLcbReadHf;
  21.    FARPROC lpfnLTellHf;
  22.    FARPROC lpfnLSeekHf;
  23.    FARPROC lpfnFEofHf;
  24.    FARPROC lpfnLcbSizeHf;
  25.    FARPROC lpfnFAccessHfs;
  26.    FARPROC lpfnRcLLInfoFromHf;
  27.    FARPROC lpfnRcLLInfoFromHfs;
  28.    FARPROC lpfnErrorW;
  29.    FARPROC lpfnErrorSz;
  30.    FARPROC lpfnGetInfo;
  31.    FARPROC lpfnAPI;                     //  Internal function of note this time
  32. } BPROC;
  33.  
  34. // ----------------------------------------------------------------------------
  35.  
  36. HINSTANCE hInst;
  37. BPROC Bp;
  38.  
  39. // ----------------------------------------------------------------------------
  40.  
  41. BOOL WINAPI DLLEntryPoint( HANDLE hDll, DWORD dwReason, LPVOID lpReserved )
  42. {
  43.    hInst = hDll;                    //  DLL starts...save instance and keep going
  44.    return( TRUE );
  45. }
  46.  
  47. // ----------------------------------------------------------------------------
  48.  
  49. LONG CALLBACK LDLLHandler( WORD wMsg, LONG lParam1, LONG lParam2 )
  50. {
  51.    switch( wMsg )
  52.    {
  53.       case 1:          //  These are apparently DW_INIT and DW_WHATMSG messages
  54.       case 4:          //  Either way, we want a return value with all bits set
  55.          return( 0xFFFFFFFFL );
  56.  
  57.       case 10:        //  DW_CALLBACKS...WinHelp passes internal functions here
  58.          memcpy( (LPVOID)&Bp, (LPVOID)lParam1,     //  Block copy the structure
  59.                  sizeof(BPROC) );             //  passed to our local structure
  60.          return( TRUE );
  61.    }
  62.    return( FALSE );
  63. }
  64.  
  65. // ----------------------------------------------------------------------------
  66. //
  67. //    Callable as a WinHelp macro to search multiple help files for a topic
  68. //
  69. // ----------------------------------------------------------------------------
  70.  
  71. BOOL CALLBACK SearchHelp( LPSTR lpPath, LPSTR lpTopic )
  72. {
  73.    HWND hHelp;
  74.    HWND hList;
  75.    HANDLE hMem;
  76.    LPSTR lpStr;
  77.    LPSTR lpFilename;
  78.    int count, i;
  79.    LONG lStatus;
  80.  
  81.                          //  Get WinHelp main window handle ot exait if invalid
  82.    hHelp = (HWND)( *Bp.lpfnGetInfo )( (WORD)GI_MAINHWND, (HWND)0 );
  83.    if( ! hHelp )
  84.       return( FALSE );
  85.                                  //  Create a hidden listbox to find help files
  86.    hList = CreateWindow( "listbox", (LPSTR)0, WS_CHILD, 0, 0, 1, 1,
  87.                          hHelp, (HMENU)-1, hInst, (LPVOID)0 );
  88.    if( ! hList )
  89.       return( FALSE );
  90.  
  91.    ShowWindow( hList, SW_HIDE );                           //  Hide the listbox
  92.    UpdateWindow( hList );
  93.  
  94.    hMem = GlobalAlloc( GHND, 512 );
  95.    if( ! hMem )
  96.    {
  97.       DestroyWindow( hList );
  98.       return( FALSE );
  99.    }
  100.  
  101.    lpStr = GlobalLock( hMem );             //  Create some string storage space
  102.    lpFilename = lpStr + 256;
  103.  
  104.    lstrcpy( lpStr, lpPath );              //  Combine path and wildcard to form
  105.    lstrcat( lpStr, "\\" );                               //  a full search path
  106.    lstrcat( lpStr, "*.HLP" );
  107.                                                //  Direct listbox to find files
  108.    SendMessage( hList, LB_DIR, (WPARAM)0x0007, (LPARAM)lpStr );
  109.    count = SendMessage( hList, LB_GETCOUNT, 0, 0 );         //  How many found?
  110.  
  111.    if( ! count )                         //  If nothing found, exit the routine
  112.    {
  113.       GlobalUnlock( hMem );
  114.       GlobalFree( hMem );
  115.  
  116.       DestroyWindow( hList );
  117.       return( FALSE );
  118.    }
  119.                                          //  Else, loop through each file found
  120.    for( i = 0; i < count; i++ )
  121.    {                                          //  Get current file from listbox
  122.       if( SendMessage( hList, LB_GETTEXT, i, (LPARAM)(LPSTR)lpStr ) )
  123.       {
  124.          lstrcpy( lpFilename, lpPath );       //  Combine with user passed path
  125.          lstrcat( lpFilename, "\\" );
  126.          lstrcat( lpFilename, lpStr );       //  Call internal WinHelp function
  127.  
  128.          lStatus = (LONG)( *Bp.lpfnAPI )( lpFilename,
  129.                                           (WORD)HELP_PARTIALKEY,
  130.                                           (DWORD)lpTopic );
  131.       }
  132.    }
  133.  
  134.    GlobalUnlock( hMem );
  135.    GlobalFree( hMem );
  136.  
  137.    DestroyWindow( hList );
  138.    return( TRUE );
  139. }
  140.  
  141.  
  142.